{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "b6242776-9002-4a4c-9f4b-f05ccb90f42f",
   "metadata": {},
   "outputs": [],
   "source": [
    "class Student(object):\n",
    "    pass"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "c2419152-7309-44f9-86d1-baa4990ca375",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Michael'"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s = Student()\n",
    "s.name = 'Michael'\n",
    "s.name"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "c64e8a5d-54d7-4c8e-8a18-abdace7ba30a",
   "metadata": {},
   "outputs": [],
   "source": [
    "def setAge(self,age):\n",
    "    self.age = age "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "3f41bcc6-7bf2-4e83-b494-f245737d97bd",
   "metadata": {},
   "outputs": [],
   "source": [
    "from types import MethodType\n",
    "s.setAge = MethodType(setAge,s)\n",
    "s.setAge(25)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "5123b88e-c1f5-4525-9f7f-bebc34a6a249",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "25"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s.age"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "0a06ed30-38c7-47c5-8748-fa450e014712",
   "metadata": {},
   "outputs": [
    {
     "ename": "AttributeError",
     "evalue": "'Student' object has no attribute 'setAge'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[8], line 2\u001b[0m\n\u001b[0;32m      1\u001b[0m s2 \u001b[38;5;241m=\u001b[39m Student()\n\u001b[1;32m----> 2\u001b[0m \u001b[43ms2\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msetAge\u001b[49m(\u001b[38;5;241m23\u001b[39m)\n",
      "\u001b[1;31mAttributeError\u001b[0m: 'Student' object has no attribute 'setAge'"
     ]
    }
   ],
   "source": [
    "s2 = Student()\n",
    "s2.setAge(23)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "7e1c3e57-542d-4024-8cf2-9fe4d7fb6ab1",
   "metadata": {},
   "outputs": [],
   "source": [
    "def setScore(self,score):\n",
    "    self.score = score\n",
    "    \n",
    "Student.setScore = setScore"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "cab746f3-a091-4c26-9968-5cbcf86b6cd5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "100"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s.setScore(100)\n",
    "s.score"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "48dd39f8-6dfd-4a1a-83bb-918c058940fa",
   "metadata": {},
   "outputs": [],
   "source": [
    "s2.setScore(80)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "3bd8bb05-076d-45ef-9a32-0a62713cf88b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "80"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s2.score"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "8f7690f2-88e1-4410-924c-504f9fea755d",
   "metadata": {},
   "outputs": [],
   "source": [
    "class Students(object):\n",
    "    __slots__ = ('name', 'age')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "5bc7d38b-70b4-4b99-be7b-5d036310eecd",
   "metadata": {},
   "outputs": [],
   "source": [
    "s = Students()\n",
    "s.name = 'Michael'\n",
    "s.age = 25"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "c1dae0f1-a65a-4d00-ad97-6556ce6745df",
   "metadata": {},
   "outputs": [
    {
     "ename": "AttributeError",
     "evalue": "'Students' object has no attribute 'score'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[25], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43ms\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mscore\u001b[49m \u001b[38;5;241m=\u001b[39m\u001b[38;5;241m99\u001b[39m\n",
      "\u001b[1;31mAttributeError\u001b[0m: 'Students' object has no attribute 'score'"
     ]
    }
   ],
   "source": [
    "s.score =99"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "471ce356-f32f-4f6b-b83d-cd4bae6cb9da",
   "metadata": {},
   "outputs": [],
   "source": [
    "class GraduateStudent(Students):\n",
    "    pass"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "edaf3d11-6b73-4f45-8c0a-1702d85dc05f",
   "metadata": {},
   "outputs": [],
   "source": [
    "g = GraduateStudent() \n",
    "g.age = 30"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "5708c806-3a30-4b22-ac6d-8de38e947c0b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "30"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "g.age"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "b3f9f435-0f2d-4b62-b2d3-d6bd79a411e3",
   "metadata": {},
   "outputs": [],
   "source": [
    "g.score = 40"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "37173b03-1004-4603-938f-95e30757e3c2",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.21"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
